package com.jingdun.sport.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingdun.sport.bean.model.ApiResult;
import com.jingdun.sport.bean.model.OptimalMotionTimeCurve;
import com.jingdun.sport.service.OptimalMotionTimeCurveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/sport/optimalMotionTimeCurve/")
@Api(tags = "最佳运动时间曲线接口")
public class OptimalMotionTimeCurveController {

    @Autowired
    private OptimalMotionTimeCurveService optimalMotionTimeCurveService;

    /**
     * 新建最佳运动时间曲线接口
     */
    @PostMapping("/addOptimalMotionTimeCurve")
    @ApiOperation(value = "新建最佳运动时间曲线接口", notes = "新建最佳运动时间曲线接口")
    public ResponseEntity<ApiResult> addOptimalMotionTimeCurve(@RequestBody OptimalMotionTimeCurve optimalMotionTimeCurve) {
        optimalMotionTimeCurveService.addOptimalMotionTimeCurve(optimalMotionTimeCurve);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 获取最佳运动时间曲线详情接口
     */
    @GetMapping("/getOptimalMotionTimeCurveDetail")
    @ApiOperation(value = "获取最佳运动时间曲线详情接口", notes = "获取最佳运动时间曲线详情接口")
    public ApiResult getOptimalMotionTimeCurveDetail(long id){
        Map m = new HashMap<String, Object>();
        m.put("id", id);
        OptimalMotionTimeCurve optimalMotionTimeCurve = optimalMotionTimeCurveService.getOptimalMotionTimeCurveDetail(m);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(optimalMotionTimeCurve);
        return apiResult;
    }

    /**
     * 删除最佳运动时间曲线接口
     */
    @PostMapping("/removeOptimalMotionTimeCurve")
    @ApiOperation(value = "删除最佳运动时间曲线接口", notes = "删除最佳运动时间曲线接口")
    public ResponseEntity removeOptimalMotionTimeCurve(long id){
        OptimalMotionTimeCurve optimalMotionTimeCurve = new OptimalMotionTimeCurve();
        optimalMotionTimeCurve.setId(id);
        optimalMotionTimeCurve.setEnabled("0");
        optimalMotionTimeCurveService.updateOptimalMotionTimeCurve(optimalMotionTimeCurve);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 修改最佳运动时间曲线接口
     */
    @PostMapping("/updateOptimalMotionTimeCurve")
    @ApiOperation(value = "修改最佳运动时间曲线接口", notes = "修改最佳运动时间曲线接口")
    public ResponseEntity updateOptimalMotionTimeCurve(@RequestBody OptimalMotionTimeCurve optimalMotionTimeCurve){
        optimalMotionTimeCurveService.updateOptimalMotionTimeCurve(optimalMotionTimeCurve);
        ApiResult apiResult = new ApiResult();
        //return ResponseEntity.ok().build();
        return ResponseEntity.ok(apiResult);
    }
    
	/**
     * 分页获取最佳运动时间曲线接口
     */
    @RequestMapping("/getPaginationOptimalMotionTimeCurve")
    @ApiOperation(value = "分页获取最佳运动时间曲线接口", notes = "分页获取最佳运动时间曲线接口")
    public ResponseEntity <ApiResult> getPaginationOptimalMotionTimeCurve(long size, long current) {
        Map m = new HashMap<String, Object>();
        m.put("size", size);
        m.put("current", current);
        Page<Map<String, Object>> page = optimalMotionTimeCurveService.getPaginationOptimalMotionTimeCurve(m);
        //return ResponseEntity.ok(page);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(page);
        return ResponseEntity.ok(apiResult);
    }

    /**
     * 分页获取最佳运动时间曲线接口
     */
    @RequestMapping("/getOptimalMotionTimeCurveList")
    @ApiOperation(value = "分页获取最佳运动时间曲线接口", notes = "分页获取最佳运动时间曲线接口")
    public ResponseEntity <ApiResult> getOptimalMotionTimeCurveList(long sportTypeId) {
        Map m = new HashMap<String, Object>();
        m.put("sportTypeId", sportTypeId);
        List<OptimalMotionTimeCurve> list = optimalMotionTimeCurveService.getOptimalMotionTimeCurveList(m);
        //return ResponseEntity.ok(list);
        ApiResult apiResult = new ApiResult();
        apiResult.setData(list);
        return ResponseEntity.ok(apiResult);
    }
    
    
}